package ru.myrtle.umf.tools.ugen.templates;

import java.io.*;
import java.text.*;
import java.util.*;
import ru.myrtle.umf.*;
import ru.myrtle.umf.codegen.*;
import ru.myrtle.umf.codegen.java.*;
import ru.myrtle.umf.tools.ugen.*;

public class UConverterStubTemplate extends UTemplate
{
    protected final String NL = System.getProperties().getProperty("line.separator");
    protected final String TEXT_1 = "package ";
    protected final String TEXT_2 = ";" + NL + NL + "public abstract class ";
    protected final String TEXT_3 = " implements UConverter {" + NL + NL + "    public static final ";
    protected final String TEXT_4 = " INSTANCE = new ";
    protected final String TEXT_5 = "();" + NL + "}" + NL;

    /*
     *
     */


    public UConverterStubTemplate() {

    }

    /*
     *
     */

    public String generate(UTemplateContext context) throws UTemplateRejectException
    {
        final StringBuffer stringBuffer = new StringBuffer();

    checkTemplateObjectType(context, UDataType.class);

    UDataType object = (UDataType) context.getObject();

    if (!object.isSerializable()) {
        reject();
    }

    String converterClassName    = UGenUtil.getConverterClassName(object);
    String converterClassPackage = UGenUtil.getConverterClassPackage(object);

    String converterStubClassName    = UGenUtil.getConverterStubClassName(object);
    String converterStubClassPackage = UGenUtil.getConverterStubClassPackage(object);

    context.getResource().setObjectFileName(converterStubClassName);
    context.getResource().setObjectFileExtension("java");
    context.getResource().setObjectPackage(converterStubClassPackage);

    JavaImportBuilder importBuilder = new JavaImportBuilder();

    importBuilder.addPackage(
        "ru.myrtle.umf.util"
    );
    importBuilder.addPackage(converterClassPackage);

        stringBuffer.append(TEXT_1);
        stringBuffer.append(converterStubClassPackage);
        stringBuffer.append(TEXT_2);
        stringBuffer.append(converterStubClassName);
        stringBuffer.append(TEXT_3);
        stringBuffer.append(converterClassName);
        stringBuffer.append(TEXT_4);
        stringBuffer.append(converterClassName);
        stringBuffer.append(TEXT_5);

    insertImport(stringBuffer, importBuilder, converterStubClassPackage);


        return stringBuffer.toString();
    }

    // ---------------------------------------------------------------------------------------
    // ---------------------------------------------------------------------------------------

}
